<?
	include('chksession.php');
	include('conn.php');
	session_start();
	
	    $prefx = $_REQUEST['prefx'];
	  $name = strtoupper($_REQUEST['name']);
      $address = $_REQUEST['address'];
	  $city = strtoupper($_REQUEST['city']);
	  $email = $_REQUEST['email'];
	  $phoneno = $_REQUEST['phoneno'];
	  $custid = $_REQUEST['custid'];
	  $custtype = strtoupper($_REQUEST['custtype']);
	   $enteredby=$_SESSION['username'];
	   $appadmchrg = $_REQUEST['appadmchrg'];
	   
	  //echo $prefx.",".$name.",".$address.",".$city.",".$custtype.",".$email.",".$phoneno.",".$custid.",".$appadmchrg;

	   //exit;
	   
		$enteredby=$_SESSION['username'];
		
		$sqlc="select count(*) cnt from customermast where status = 0 and custdesc='".$name."'";
		$resc=mysql_query($sqlc);
		$rowc=mysql_fetch_assoc($resc);
		if (strlen($name)>1)
		{
			if($rowc['cnt']==0)
			{
				$sql="insert into customermast(custtype,prefx,custdesc,address,city,email,phoneno, appadmchrg,enteredby,entrydt)
				values('$custtype','$prefx','$name','$address','$city','$email','$phoneno',$appadmchrg,'$enteredby',sysdate())";
				
				
				$res=mysql_query($sql);
				if($res)
					$msg='Record saved successfully';			
			}
			else
			{
				$sql="update customermast set custdesc='$name',custtype='$custtype',address='$address',city='$city',email='$email',phoneno='$phoneno',prefx='$prefx',enteredby='$enteredby',appadmchrg=$appadmchrg,entrydt=sysdate()	where status=0 and custid=$custid";
		
				
				
				$res=mysql_query($sql);
				if($res)
					$msg='Record updated successfully...';					
			}
		}
		else
		{
			$msg='Blank Name not Allowed';
		}			
	    echo $msg;
?>